package limeirafol.gui.Cadastro;

import limeirafol.bean.BeanCadastro;
import limeirafol.gui.MenuGUI;
import limeirafol.gui.ParametroGUI;
import limeirafol.remote.cadastro.AcessorioVO;
import limeirafol.remote.cadastro.ProdutoItemVO;
import limeirafol.remote.cadastro.tipoEmbalagem;
import org.openide.util.Exceptions;
import lbframework.bean.consultaCampo.LBConsultaCampo;
import lbframework.bean.internalFrame.LBInternalFrame;
import lbframework.bean.mdiFrame.LBMdiFrame;
import lbframework.classe.Util;
import lbframework.classe.LBException;

public class ProdutoCadastroItensGUI extends LBInternalFrame {

    private ProdutoItemVO oProdutoAcessorio = null;
    private ProdutoCadastroGUI parentFrame = null;
    BeanCadastro beanCadastro = new BeanCadastro();
    private int index = 0;
    private boolean alteracao = false;

    public ProdutoCadastroItensGUI(LBMdiFrame i_mdiFrame, ProdutoCadastroGUI i_parentFrame) throws Exception {
        super(i_mdiFrame);
        initComponents();
        centralizarForm();

        this.setMaximizable(false);
        this.setResizable(false);

        parentFrame = i_parentFrame;

        cboBanhoAcessorio.setTabela("banho");
        cboBanhoAcessorio.setFiltro("WHERE banhoacessorio = true");
        cboBanhoAcessorio.setCampoOrdenacao("id", "");
        cboBanhoAcessorio.carregar();



        cnsAcessorios.setTabela("acessorios");
        cnsAcessorios.addRetorno("id_tipoembalagem", LBConsultaCampo.INT);

        cboTipoEmbalagem.setTabela("tipoembalagem");
        cboTipoEmbalagem.carregar();
        cboTipoEmbalagem.setId(-1);
        cboTipoEmbalagem.setEnabled(false);

    }

    @Override
    public void incluir() throws Exception {
        verificarAlteracaoTela();

        cnsAcessorios.clear();
        cboTipoEmbalagem.setId(-1);
        txtQuantidade.setText("");
        //cboBanhoAcessorio.setId(-1);
        txtCustoAcessorio.setText("");
        txtPesoAcess.setText("");
        txtCustoTotal.setText("");
        txtPesoTotal.setText("");

        cnsAcessorios.setEnabled(true);

        oProdutoAcessorio = new ProdutoItemVO();
        alteracao = false;

        cnsAcessorios.requestFocus();

        getEstadoTelaInicial();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        vRToolBarPadrao1 = new lbframework.bean.toolBarPadrao.LBToolBarPadrao(this);
        vRPanel1 = new lbframework.bean.panel.LBPanel();
        vRLabel1 = new lbframework.bean.label.LBLabel();
        cnsAcessorios = new lbframework.bean.consultaCampo.LBConsultaCampo();
        vRLabel2 = new lbframework.bean.label.LBLabel();
        cboTipoEmbalagem = new lbframework.bean.comboBox.LBComboBox();
        vRLabel3 = new lbframework.bean.label.LBLabel();
        txtQuantidade = new lbframework.bean.textField.LBTextField();
        vRLabel4 = new lbframework.bean.label.LBLabel();
        cboBanhoAcessorio = new lbframework.bean.comboBox.LBComboBox();
        vRPanel2 = new lbframework.bean.panel.LBPanel();
        lblcusto = new lbframework.bean.label.LBLabel();
        txtCustoAcessorio = new lbframework.bean.textField.LBTextField();
        txtPesoAcess = new lbframework.bean.textField.LBTextField();
        vRLabel9 = new lbframework.bean.label.LBLabel();
        txtPesoTotal = new lbframework.bean.textField.LBTextField();
        vRLabel10 = new lbframework.bean.label.LBLabel();
        txtCustoTotal = new lbframework.bean.textField.LBTextField();
        vRLabel11 = new lbframework.bean.label.LBLabel();
        vRPanel3 = new lbframework.bean.panel.LBPanel();
        vRButton1 = new lbframework.bean.button.LBButton();
        vRButton2 = new lbframework.bean.button.LBButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        vRToolBarPadrao1.setRollover(true);
        vRToolBarPadrao1.setVisibleIncluir(true);
        vRToolBarPadrao1.setVisibleParametrizar(true);
        vRToolBarPadrao1.setVisibleSalvar(true);

        vRLabel1.setText("Acessório");

        cnsAcessorios.setObrigatorio(true);
        cnsAcessorios.addEventoConsultaCampoListener(new lbframework.bean.consultaCampo.LBEventoConsultaCampoListener() {
            public void abreTelaConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {
                cnsAcessoriosAbreTelaConsulta(evt);
            }
            public void aposConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {
                cnsAcessoriosAposConsulta(evt);
            }
        });

        vRLabel2.setText("Tipo Embalagem");

        cboTipoEmbalagem.setEnabled(false);

        vRLabel3.setText("Quantidade");

        txtQuantidade.setObrigatorio(true);
        txtQuantidade.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtQuantidadeFocusLost(evt);
            }
        });

        vRLabel4.setText("Banho do Acessório");

        javax.swing.GroupLayout vRPanel1Layout = new javax.swing.GroupLayout(vRPanel1);
        vRPanel1.setLayout(vRPanel1Layout);
        vRPanel1Layout.setHorizontalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cnsAcessorios, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cboTipoEmbalagem, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cboBanhoAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        vRPanel1Layout.setVerticalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(vRLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboBanhoAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(vRLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cnsAcessorios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboTipoEmbalagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblcusto.setText("Custo Acess.");

        txtCustoAcessorio.setEnabled(false);

        txtPesoAcess.setEnabled(false);
        txtPesoAcess.setMascara("Decimal 3");

        vRLabel9.setText("Peso Acess");

        txtPesoTotal.setEnabled(false);
        txtPesoTotal.setMascara("Decimal 3");

        vRLabel10.setText("Peso Total");

        txtCustoTotal.setEnabled(false);
        txtCustoTotal.setMascara("Decimal 3");

        vRLabel11.setText("Custo Total");

        javax.swing.GroupLayout vRPanel2Layout = new javax.swing.GroupLayout(vRPanel2);
        vRPanel2.setLayout(vRPanel2Layout);
        vRPanel2Layout.setHorizontalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblcusto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCustoAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPesoAcess, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCustoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPesoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(326, Short.MAX_VALUE))
        );
        vRPanel2Layout.setVerticalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel2Layout.createSequentialGroup()
                        .addComponent(vRLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel2Layout.createSequentialGroup()
                        .addComponent(vRLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCustoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel2Layout.createSequentialGroup()
                        .addComponent(vRLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesoAcess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel2Layout.createSequentialGroup()
                        .addComponent(lblcusto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCustoAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        vRButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/salvar.png"))); // NOI18N
        vRButton1.setText("Salvar");
        vRButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vRButton1ActionPerformed(evt);
            }
        });

        vRButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/sair.png"))); // NOI18N
        vRButton2.setText("Sair");
        vRButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vRButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout vRPanel3Layout = new javax.swing.GroupLayout(vRPanel3);
        vRPanel3.setLayout(vRPanel3Layout);
        vRPanel3Layout.setHorizontalGroup(
            vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, vRPanel3Layout.createSequentialGroup()
                .addContainerGap(500, Short.MAX_VALUE)
                .addComponent(vRButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        vRPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {vRButton1, vRButton2});

        vRPanel3Layout.setVerticalGroup(
            vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(vRButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(vRButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(vRPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(vRPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(vRPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cnsAcessoriosAbreTelaConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {//GEN-FIRST:event_cnsAcessoriosAbreTelaConsulta

        try {
            MenuGUI menu = (MenuGUI) mdiFrame;

            if (menu.formAcessorioConsulta == null || menu.formAcessorioConsulta.isClosed()) {
                menu.formAcessorioConsulta = new AcessorioConsultaGUI(mdiFrame);
            }

            menu.formAcessorioConsulta.setConsultaCampo(cnsAcessorios);
            menu.formAcessorioConsulta.setVisible(true);

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }

    }//GEN-LAST:event_cnsAcessoriosAbreTelaConsulta

    private void cnsAcessoriosAposConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {//GEN-FIRST:event_cnsAcessoriosAposConsulta

        try {
            cboTipoEmbalagem.setId(cnsAcessorios.getInt("id_tipoembalagem"));


            atualizaPrecoPesoAcessorio();

        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }

    }//GEN-LAST:event_cnsAcessoriosAposConsulta

    private void txtQuantidadeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQuantidadeFocusLost
        try {
            if (!(txtQuantidade.getText().equals(""))) {
                if (txtQuantidade.getDouble() == 0) {
                    Util.exibirMensagem("O Valor não pode ser 0", getTitle());
                    txtQuantidade.requestFocusLater();

                } else {
                    calculaValores();
                }
            }
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }

    }//GEN-LAST:event_txtQuantidadeFocusLost

    public void carregarProduto(int i_index) throws Exception {
        oProdutoAcessorio = parentFrame.oProdutoCadastro.vItem.get(i_index).getCopia();
        index = i_index;

        alteracao = true;

        cnsAcessorios.setId(oProdutoAcessorio.idAcessorio);
        cnsAcessorios.consultar();
        cboTipoEmbalagem.setId(oProdutoAcessorio.idTipoEmbalagem);
        cboBanhoAcessorio.setId(oProdutoAcessorio.idTipoBanho);
        if (cnsAcessorios.getInt("id_tipoembalagem") == tipoEmbalagem.KG.getId()) {
            txtQuantidade.setMascara("Decimal 3");
            lblcusto.setText("Custo Acess. (KG)");
            txtCustoAcessorio.setMascara("Decimal 2");


        } else {
            txtQuantidade.setMascara("Decimal 0");
            txtCustoAcessorio.setMascara("Decimal 3");
            lblcusto.setText("Custo Acess.");

        }
        txtQuantidade.setDouble(oProdutoAcessorio.quantidade);


        cnsAcessorios.setEnabled(false);
        atualizaPrecoPesoAcessorio();
        calculaValores();

        getEstadoTelaInicial();
    }

    @Override
    public void salvar() throws Exception {
        Util.validarCampoTela(this.getCampoObrigatorio());

        oProdutoAcessorio = new ProdutoItemVO();

        oProdutoAcessorio.idAcessorio = cnsAcessorios.getId();
        oProdutoAcessorio.acessorio = cnsAcessorios.getDescricao();
        oProdutoAcessorio.idTipoEmbalagem = cboTipoEmbalagem.getId();
        oProdutoAcessorio.tipoEmbalagem = cboTipoEmbalagem.getDescricao();

        if (cboTipoEmbalagem.getId() == tipoEmbalagem.KG.getId()) {
            oProdutoAcessorio.quantidade = txtQuantidade.getDouble();
        } else {
            oProdutoAcessorio.quantidade = txtQuantidade.getInt();
        }
        oProdutoAcessorio.idTipoBanho = cboBanhoAcessorio.getId();
        oProdutoAcessorio.tipoBanho = cboBanhoAcessorio.getDescricao();
        oProdutoAcessorio.custoUnitario = txtCustoAcessorio.getDouble();
        oProdutoAcessorio.pesoUnitario = txtPesoAcess.getDouble();
        oProdutoAcessorio.custoTotal = txtCustoTotal.getDouble();
        oProdutoAcessorio.pesoTotal = txtPesoTotal.getDouble();

        if (!alteracao) {
            for (ProdutoItemVO oItem : parentFrame.oProdutoCadastro.vItem) {
                if (oItem.idAcessorio == oProdutoAcessorio.idAcessorio && oItem.idTipoBanho == oProdutoAcessorio.idTipoBanho) {
                    throw new LBException("Acessório já Cadastrado");
                }
            }
            parentFrame.oProdutoCadastro.vItem.add(oProdutoAcessorio);
        } else {
            parentFrame.oProdutoCadastro.vItem.set(index, oProdutoAcessorio);
        }

        parentFrame.exibirAcessorio();

        getEstadoTelaInicial();
        
        if (!alteracao) {
            incluir();
        } else {
            sair();
        }
    }

    private void vRButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vRButton2ActionPerformed
        try {
            verificarAlteracaoTela();
            sair();

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }

    }//GEN-LAST:event_vRButton2ActionPerformed

    private void vRButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vRButton1ActionPerformed
        try {
            salvar();

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }
    }//GEN-LAST:event_vRButton1ActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        try {
            verificarAlteracaoTela();
            sair();

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }
    }//GEN-LAST:event_formInternalFrameClosing
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private lbframework.bean.comboBox.LBComboBox cboBanhoAcessorio;
    private lbframework.bean.comboBox.LBComboBox cboTipoEmbalagem;
    private lbframework.bean.consultaCampo.LBConsultaCampo cnsAcessorios;
    private lbframework.bean.label.LBLabel lblcusto;
    private lbframework.bean.textField.LBTextField txtCustoAcessorio;
    private lbframework.bean.textField.LBTextField txtCustoTotal;
    private lbframework.bean.textField.LBTextField txtPesoAcess;
    private lbframework.bean.textField.LBTextField txtPesoTotal;
    private lbframework.bean.textField.LBTextField txtQuantidade;
    private lbframework.bean.button.LBButton vRButton1;
    private lbframework.bean.button.LBButton vRButton2;
    private lbframework.bean.label.LBLabel vRLabel1;
    private lbframework.bean.label.LBLabel vRLabel10;
    private lbframework.bean.label.LBLabel vRLabel11;
    private lbframework.bean.label.LBLabel vRLabel2;
    private lbframework.bean.label.LBLabel vRLabel3;
    private lbframework.bean.label.LBLabel vRLabel4;
    private lbframework.bean.label.LBLabel vRLabel9;
    private lbframework.bean.panel.LBPanel vRPanel1;
    private lbframework.bean.panel.LBPanel vRPanel2;
    private lbframework.bean.panel.LBPanel vRPanel3;
    private lbframework.bean.toolBarPadrao.LBToolBarPadrao vRToolBarPadrao1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void parametrizar() throws Exception {
        ParametroGUI form = new ParametroGUI(mdiFrame);

        form.carregarParametro(3, 4, 5);
        form.setVisible(true);
    }

    public void atualizaPrecoPesoAcessorio() throws Exception {

        if (cnsAcessorios.getInt("id_tipoembalagem") == tipoEmbalagem.KG.getId()) {
            txtQuantidade.setMascara("Decimal 3");
            lblcusto.setText("Custo Acess. (KG)");
            txtCustoAcessorio.setMascara("Decimal 2");


        } else {
            txtQuantidade.setMascara("Decimal 0");
            txtCustoAcessorio.setMascara("Decimal 3");
            lblcusto.setText("Custo Acess.");

        }

        AcessorioVO oAcessorio = new AcessorioVO();
        oAcessorio = beanCadastro.carregarAcessorio(cnsAcessorios.getId());
        txtCustoAcessorio.setDouble(oAcessorio.custoUnitario);
        txtPesoAcess.setDouble(oAcessorio.pesoUnitario);
    }

    public void calculaValores() throws Exception {
        double custoTotal = 0;

        if (cnsAcessorios.getInt("id_tipoembalagem") == tipoEmbalagem.KG.getId()) {
            custoTotal = (txtCustoAcessorio.getDouble() * txtQuantidade.getDouble());
            txtPesoTotal.setDouble(txtQuantidade.getDouble());
        } else {
            custoTotal = txtCustoAcessorio.getDouble() * txtQuantidade.getDouble();
            txtPesoTotal.setDouble(txtQuantidade.getDouble() * txtPesoAcess.getDouble());
        }
        txtCustoTotal.setDouble(custoTotal);

    }
}
